//
//  ViewController.m
//  CustomCell
//
//  Created by apple on 2017/3/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ViewController.h"
#import "CustomCell.h"        //1
#import "CustomCell2.h"

@interface ViewController () <CustomCellDelegate,UITableViewDelegate,UITableViewDataSource>    //2
@property (nonatomic, strong) NSArray *listTeams;   //3

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSBundle *bundle = [NSBundle mainBundle];                                  //4
    NSString *plistPath = [bundle pathForResource:@"team" ofType:@"plist"];//5
    //获取属性列表文件中的全部数据
    self.listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath];//6
    [self.tabelView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"CustomCell"];
    [self.tabelView registerNib:[UINib nibWithNibName:@"CustomCell2" bundle:nil] forCellReuseIdentifier:@"CustomCell2"];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --UITableViewDataSource协议
- (NSInteger)tableView:(UITableView *)tabelView numberOfRowsInSection:(NSInteger)section {
    return [self.listTeams count]; //7
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row % 2 == 0) {
        static NSString *cellIdentifier = @"CustomCell";
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        cell.delegate = self;//important
        [cell configCell:self.listTeams[indexPath.row]];
        return cell;
    }else{
        static NSString *cellIdentifier = @"CustomCell2";
        CustomCell2 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"CustomCell2" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row %2 == 0) {
        return 44.0f;
    }else{
        return 170.0f;
    }
}

- (void)sendValue:(NSString *)value
{
    self.topLabel.text=value;
    
    //_topLabel.text=value;
}



@end
